package org.jeecg.modules.yks.mqtt.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.api.vo.Result;
import org.jeecg.modules.yks.config.MqttConfig;
import org.jeecg.modules.yks.mqtt.service.MqttGateway;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

//import io.swagger.annotations.Api;
//import io.swagger.annotations.ApiOperation;

@Api(tags = "MQTT发布订阅测试管理")
@RestController
@RequestMapping("/mqtt")
public class MqttController {
	@Autowired
    private MqttGateway mqttGateway;
	@Autowired
	private MqttConfig mqttConfig;
 
	@ApiOperation("发送消息")
    @GetMapping("/send_data/{topic}")
    public Result<Object> sendMqtt(String  sendData, @PathVariable String topic){
        mqttGateway.sendToMqtt(sendData,topic);
        return Result.ok();
    }
	
	@ApiOperation("注册监听主题")
	@GetMapping("/add_topic")
	public Result<Object> addTopic(String[] topic) {
		mqttConfig.addListenTopic(topic);
		return Result.ok();
	}
	
	@ApiOperation("删除监听主题")
	@GetMapping("/delete_topic")
	public Result<Object> delete(String topic) {
		mqttConfig.removeListenTopic(topic);
		return Result.ok();
	}
}
